using Microsoft.Practices.CompositeWeb;
using PageFlowQuickstart.Modules.Customers.BusinessEntities;
using Microsoft.Practices.ObjectBuilder;

namespace PageFlowQuickstart.Modules.Customers.Views
{
    public class CustomerDetailsViewPresenter : Presenter<ICustomerDetailsView>
    {
        private CustomersController _controller;

        public CustomerDetailsViewPresenter([CreateNew] CustomersController controller)
        {
            _controller = controller;
        }

        public void OnApproveCustomer()
        {
            _controller.ApproveCurrentCustomer();
        }

        public override void OnViewInitialized()
        {
            Customer customer = _controller.CurrentCustomer;
            if (customer == null)
            {
                View.ShowCustomerDetails = false;
                View.AllowApproveCustomer = false;
            }
            View.Customer = customer;
        }
    }
}
